<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
	<%@ include file="/base/jsp/include.jsp"%>
  </head>
  <body>
    <form id="form" method="post">
        <input name="id" class="mini-hidden" />
        <fieldset style="border:solid 1px #aaa;padding:10px;">
            <legend >添加图片</legend>
            <div style="padding:5px;">
            <table class="editor_table">

                <tr>
                    <td style="width:70px;">日期：</td>
                    <td style="width:150px;">
                        <input name="date" id="date" class="mini-datepicker" format="yyyy-MM-dd" required="true"/>
                    </td>
                </tr>
                <!--首页图-->
                <tr>
                    <td style="width:70px;">上传首页图：</td>
                    <td style="width:150px;">
                    	<!--fileCountLimit:上限 multi:是否为多文件 showImage:是否为图片  fileType:文件类型 fileSize:文件大小限制 buttonText:按钮文本 -->
                      <input id="file_upload" fileCountLimit="1" multi="true" type="file" 
                      	showImage="true" onuploadsuccess="onUploadSuccess"  fileType="*.jpg;*.jpeg;*.png" fileSize="1MB" buttonText="上传图标"/>
                    </td>
                </tr>
                <tr style="display:none;">
                    <td style="width:200px;">文件ID：</td>
                    <td style="width:150px;">
                    	<input name="img" id="img" class="mini-textbox" required="true" vtype="maxLength:100" emptyText="图片id"/>
                    </td>
                </tr>
                <!--功能页一图-->
                <tr>
                    <td style="width:70px;">上传功能页一图：（科目那儿的）</td>
                    <td style="width:150px;">
                    	<!--fileCountLimit:上限 multi:是否为多文件 showImage:是否为图片  fileType:文件类型 fileSize:文件大小限制 buttonText:按钮文本 -->
                      <input id="file_upload_gn2" fileCountLimit="1" multi="true" type="file" 
                      	showImage="true" onuploadsuccess="onUploadSuccessGn2"  fileType="*.jpg;*.jpeg;*.png" fileSize="1MB" buttonText="上传图标"/>
                    </td>
                </tr>
                <tr style="display:none;">
                    <td style="width:200px;">文件ID：</td>
                    <td style="width:150px;">
                    	<input name="imgGn2" id="imgGn2" class="mini-textbox" required="true" vtype="maxLength:100" emptyText="图片id"/>
                    </td>
                </tr>
                 <!--功能页二图-->
                <tr>
                    <td style="width:70px;">上传功能页二图：（广场精华那儿的）</td>
                    <td style="width:150px;">
                    	<!--fileCountLimit:上限 multi:是否为多文件 showImage:是否为图片  fileType:文件类型 fileSize:文件大小限制 buttonText:按钮文本 -->
                      <input id="file_upload_gn3" fileCountLimit="1" multi="true" type="file" 
                      	showImage="true" onuploadsuccess="onUploadSuccessGn3"  fileType="*.jpg;*.jpeg;*.png" fileSize="1MB" buttonText="上传图标"/>
                    </td>
                </tr>
                <tr style="display:none;">
                    <td style="width:200px;">文件ID：</td>
                    <td style="width:150px;">
                    	<input name="imgGn3" id="imgGn3" class="mini-textbox" required="true" vtype="maxLength:100" emptyText="图片id"/>
                    </td>
                </tr>
                <!--足迹图-->
                <tr>
                    <td style="width:70px;">上传足迹图：</td>
                    <td style="width:150px;">
                    	<!--fileCountLimit:上限 multi:是否为多文件 showImage:是否为图片  fileType:文件类型 fileSize:文件大小限制 buttonText:按钮文本 -->
                      <input id="file_upload_zj" fileCountLimit="1" multi="true" type="file" 
                      	showImage="true" onuploadsuccess="onUploadSuccessZj"  fileType="*.jpg;*.jpeg;*.png" fileSize="1MB" buttonText="上传图标"/>
                    </td>
                </tr>
                <tr style="display:none;">
                    <td style="width:200px;">文件ID：</td>
                    <td style="width:150px;">
                    	<input name="imgZj" id="imgZj" class="mini-textbox" required="true" vtype="maxLength:100" emptyText="图片id"/>
                    </td>
                </tr>
               
                
            </table>            
         </div>
        </fieldset>
        
        <div style="text-align:center;padding:10px;">  
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;margin-right:20px">取消</a>
            <a class="mini-button" onclick="onClearFile" style="width:100px;margin-right:20px;">清除首页图</a>
            <a class="mini-button" onclick="onClearFileGn2" style="width:100px;margin-right:20px;">清除功能页一</a>
            <a class="mini-button" onclick="onClearFileGn3" style="width:100px;margin-right:20px;">清除功能页二</a>
            <a class="mini-button" onclick="onClearFileZj" style="width:100px;">清除足迹</a>     
        </div>        
    </form>
    
    <script type="text/javascript">
    	var id = '';
        mini.parse();
        var form = new mini.Form("form");
        function SaveData() {
			var o = form.getData(true);
            form.validate();
            if (form.isValid() == false) return;
            var json = mini.encode(o);
            //mini.alert(json);
            $.ajax({
                url: "saveMedia.do",
                type: 'post',
                data: $.evalJSON(json),
                cache: false,
                success: function (text) {
                	if(text.indexOf('true') > -1){
				    	mini.alert("操作成功");
				    	CloseWindow("save");
				    }else if(text.indexOf('false') > -1){
				    	mini.alert("操作失败");
				    	CloseWindow();
				    }else if(text.indexOf('date') > -1){
				    	mini.alert("该日期已有了推荐图片");
				    	//CloseWindow();
				    }
                },
                error: function (textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }
        
        //标准方法接口定义
        function SetData(data) {
            if (data.action == "edit") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                $.ajax({
                    url: "findByIdMedia.do?id=" + data.id,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);
                        id = o.id;
                        var imgs = mini.get("img").getValue();
                        var imgGn2 = mini.get("imgGn2").getValue();
                        var imgGn3 = mini.get("imgGn3").getValue();
                        var imgZj = mini.get("imgZj").getValue();
                        if(imgs != ''){
               			 $('#file_upload').setFileId(imgs,true,true);
               		    }
               		    if(imgGn2 != ''){
               			 $('#file_upload_gn2').setFileId(imgGn2,true,true);
               		    }
               		    if(imgGn3 != ''){
               			 $('#file_upload_gn3').setFileId(imgGn3,true,true);
               		    }
               		    if(imgZj != ''){
               			 $('#file_upload_zj').setFileId(imgZj,true,true);
               		    }
                    }
                });
            }
        }

        function GetData() {
            var o = form.getData();
            return o;
        }
        
        function CloseWindow(action) {
            if (action == "cancel" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                	SaveData();
                	return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();            
        }
        function onOk(e) {
        	/*var imgId = mini.get("img").getValue();
        	if(imgId == ""){
        		mini.alert("请上传图片");
        		return ;
        	}
        	*/
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        function onClearFile(e){
            $("#file_upload").clearFileId();
        	mini.get("img").setValue("");
        }
        function onClearFileGn2(e){
            $("#file_upload_gn2").clearFileId();
        	mini.get("imgGn2").setValue("");
        }
         function onClearFileGn3(e){
            $("#file_upload_gn3").clearFileId();
        	mini.get("imgGn3").setValue("");
        }
         function onClearFileZj(e){
            $("#file_upload_zj").clearFileId();
        	mini.get("imgZj").setValue("");
        }
        function onUploadSuccess(e) {
              mini.get("img").setValue($("#file_upload").getFileId());
        }
        function onUploadSuccessGn2(e) {
              mini.get("imgGn2").setValue($("#file_upload_gn2").getFileId());
        }
        function onUploadSuccessGn3(e) {
              mini.get("imgGn3").setValue($("#file_upload_gn3").getFileId());
        }
        function onUploadSuccessZj(e) {
              mini.get("imgZj").setValue($("#file_upload_zj").getFileId());
        }
    </script>
  </body>
</html>
